package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.service.ContentCateGoryService;
import com.dongdongshop.vo.ContentCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("contentCateGory")
public class ContentCateGoryController {
    @Autowired
    private ContentCateGoryService contentCateGoryService;

    @GetMapping("getAllContentCateGory")
    public Result getAllContentCateGory(){
        List<ContentCategoryVO> categoryVOS = contentCateGoryService.getAllContentCateGory();
        return Result.OK().setData(categoryVOS);
    }

    @PostMapping("addContentCateGory")
    public Result addContentCateGory(@RequestBody ContentCategoryVO contentCategoryVO){
       int  i =contentCateGoryService.addContentCateGory(contentCategoryVO);
       if(i >= 1){
           return Result.OK();
       }
       return Result.FAIL();
    }

    @PostMapping("getContentCateGoryById/{id}")
    public Result getContentCateGoryById(@PathVariable("id") Long id){
        ContentCategoryVO contentCategoryVO =  contentCateGoryService.getContentCateGoryById(id);
        return Result.OK().setData(contentCategoryVO);
    }

    @PostMapping("updateContentCateGory")
    public Result updateContentCateGory(@RequestBody ContentCategoryVO contentCategoryVO){
        int  i =contentCateGoryService.updateContentCateGory(contentCategoryVO);
        if(i >= 1){
            return Result.OK();
        }
        return Result.FAIL();
    }

    @PostMapping("deleteBatch")
    public Result deleteBatch(@RequestBody List<Long> ids){
        int  i =contentCateGoryService.deleteBatch(ids);
        if(i >= 1){
            return Result.OK();
        }
        return Result.FAIL();
    }
}
